import operate from '@dfeidao/atom-nodejs/db/operate';
import uuid from 'uuid';
interface Message {
	pub_form_code: [];
	formid: string;
	productid: string;
}
interface PubFormCode {
	code: string;			// 编码
	action_keyword: string;	// 控制点关键字
	action_name: string;	// 控制点名称

}
export default async function atom(msg: Message, action_id: string, session_id: string) {
	const { exec: e3, insert: p3 } = operate(action_id, session_id, '12');
	Array.from(msg.pub_form_code).forEach((v: PubFormCode) => {
		p3('pub_form_code', {
			_id: uuid(),
			formid: msg.formid,
			code: v.code,
			action_keyword: v.action_keyword,
			action_name: v.action_name,
			productid: msg.productid,
			source_flag: 0
		});
	});
	const ret = await e3();
	if (ret.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
